package app.mvp.contract;

import java.io.Serializable;

import app.mvp.MainModel;
import app.mvp.base_mvp.BaseModel;
import app.mvp.base_mvp.BaseMvpModel;
import app.mvp.base_mvp.BasePresenter;

/**
 * Created by 刘智强 on 2017/5/3.
 */

public class LoginContract {


    public interface LoginView {

        void loginSuccess();

        void loginFailed();

        void showMessage(String msg);
    }

    public abstract class LoginPresenter extends BasePresenter {
        public void login(String name, String password) {
            LoginModel loginModel = null;
            LoginView loginView = null;
            loginView = (LoginView) view;
            loginModel = (LoginModel) model;
            MainModel mainModel = loginModel.getModel();
            if (!name.isEmpty() && !password.isEmpty()) {
                if (!name.equals(mainModel.getName())) {
                    loginView.showMessage("账号不存在!!!");
                    loginView.loginFailed();

                } else if (!password.equals(mainModel.getAge())) {
                    loginView.showMessage("密码不正确!!!");
                    loginView.loginFailed();
                } else if (name.equals(mainModel.getName()) && password.equals(mainModel.getAge())) {
                    loginView.showMessage("登陆成功!!!");
                    loginView.loginSuccess();

                }

            } else {
                loginView.showMessage("账号或者密码不能为空");
                loginView.loginFailed();
            }

        }
    }

    public class LoginModel implements BaseModel, Serializable {

        @Override
        public MainModel getModel() {
            return new MainModel(1003, "admin", 123456);
        }
    }


}